package com.xxx.video.channel.activitys;

import android.os.Bundle;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.xxx.video.R;
import com.xxx.video.channel.adapters.ChannelListAdapter;
import com.xxx.video.channel.beans.TypeInfoBean;
import com.xxx.video.channel.presenters.ChannelListPresenter;
import com.xxx.video.channel.presenters.IChannelListView;
import com.xxx.video.commen.activitys.BaseActivity;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.utils.ListUtils;
import com.xxx.video.commen.utils.StatusBarUtil;
import com.xxx.video.main.activitys.VideoDetailsActivity;
import com.xxx.video.main.beans.VideoListBean;

import butterknife.BindView;

public class ChannelListActivity extends BaseActivity<ChannelListPresenter> implements IChannelListView, BaseRecycleViewAdapter.OnItemClickListener<VideoListBean> {

    @BindView(R.id.rcv_channel_list)
    RecyclerView rcvChannelList;
    /**
     * id
     */
    private String mId;

    @Override
    public void initToolbarData() {
        super.initToolbarData();
        showActionBar();
        StatusBarUtil.getInstance().setStatusBarTransparent(this, true);
        setIsShowActionbarLine(true);
    }

    @Override
    protected ChannelListPresenter createPresenter() {
        return new ChannelListPresenter(this, this);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_channel_list;
    }

    @Override
    public void initData(Bundle extras) {
        if (extras != null) {
            mId = extras.getString("Id");
        }
        getPresenter().getTypeInfo(mId);
    }

    @Override
    public void showRootLayoutStatus(int status) {
        showLayoutStatus(status);
    }


    @Override
    public void initData2View(TypeInfoBean successOb) {
        rcvChannelList.setLayoutManager(new GridLayoutManager(this, 2));
        ChannelListAdapter channelListAdapter = new ChannelListAdapter(this);
        rcvChannelList.setAdapter(channelListAdapter);
        channelListAdapter.setOnItemClickListener(this);
        channelListAdapter.setData(successOb.applist);
        if (ListUtils.isEmpty(successOb.applist)) {
            showRootLayoutStatus(2);
        } else {
            showRootLayoutStatus(1);
        }
        if (successOb.info != null) {
            /*
             * init title
             */
            setActionBarTitle(successOb.info.fName);
        }
    }

    @Override
    public void startAppDetailsActivity(String videoId) {
        Bundle bundle = new Bundle();
        bundle.putString("Id", videoId);
        intent2Activity(VideoDetailsActivity.class, bundle);
    }

    @Override
    public void onItemClick(VideoListBean videoListBean, int position, int type) {
        startAppDetailsActivity(videoListBean.fId);
    }
}
